<?php

class edit_block
{
	var $label, $mode, $select_sql, $value_id, $display_major, $display_minor, $use_minor, $display_remove, $select_id;
	
	function edit_block($mode, $label, $select_sql, $value_id, $display_major, $display_minor = '', $display_remove=true, $select_id=-1)
	{
		if($display_minor == '')
		{
			$this->use_minor = false;
		}
		else
		{
			$this->display_minor = $display_minor;
			$this->use_minor = true;
		}
		$this->display_remove = $display_remove;
		$this->label = $label;
		$this->mode = $mode;
		$this->select_sql = $select_sql;
		$this->display_major = $display_major;
		$this->value_id = $value_id;
		$this->select_id = $select_id;
	}


	function render()
	{
		global $skin_dir, $db, $lang;
		
		$currentItems = '';
		$label = $lang[$this->label];
		$mode = $this->mode;
		$result = $db->sql_query($this->select_sql);
		//echo $this->select_sql;
		$remS = $this->display_remove ? '' : '<!--';
		$remE = $this->display_remove ? '' : '-->';
		
		while($row = $db->sql_fetchrow($result)) {
			
			
			$row = formatArrayOutput($row, true);
			$selected = '';
			if($row[$this->value_id]==$this->select_id)
				$selected = 'SELECTED';
				
			if($this->use_minor)
			{
				$currentItems = $currentItems . '<option value="' . $row[$this->value_id] . '" ' . $selected . '>' . $row[$this->display_major] . 
										' (' . $row[$this->display_minor] . ')</option>';
			}
			else
			{
				$currentItems = $currentItems . '<option value="' . $row[$this->value_id] .'" ' . $selected . '>' . $row[$this->display_major] . '</option>';
			}
		}
		
		include $skin_dir . 'admin/editblock.tpl';
		
	}
}

?>